<template>
  <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="dialogFormVisible" width="500px" @close="close"
    :append-to-body="true">
    <el-form ref="form" :model="form" :rules="rules" label-width="0.8rem">
      <el-form-item label="货位编号" prop="huoweibh">
        <el-input v-model.trim="form.huoweibh" autocomplete="off" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="货位分类">
        <el-select v-model="form.huoweifl" placeholder="请选择">
          <el-option v-for="( item, index ) in $util.getHwlx() " :key="index" :label="item.name"
            :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="货位状态">
        <el-select v-model="form.huoweizt" placeholder="请选择">
          <el-option v-for="( item, index ) in ztlist " :key="index" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="层">
        <el-input v-model.trim="form.ceng" autocomplete="off" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="排">
        <el-input v-model.trim="form.pai" autocomplete="off" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="列">
        <el-input v-model.trim="form.lie" autocomplete="off" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="仓库名称">
        <el-input v-model.trim="form.cangkumc" autocomplete="off" placeholder="请输入"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { AddHuowei, UptHuowei } from '@/api/cangkujichu'
export default {
  name: 'LocationManagementEdit',
  data() {
    return {
      form: {
        huoweibh: "",
        huoweifl: "",
        huoweizt: "",
        ceng: "",
        pai: "",
        lie: "",
        cangkumc: "",
      },
      rules: {
        huoweibh: [
          { required: true, trigger: 'blur', message: '请输入编号' },
        ],
      },
      title: '',
      dialogFormVisible: false,
      ztlist: [
        {
          id: 1,
          name: '空闲'
        },
        {
          id: 2,
          name: '占用'
        },
        {
          id: 3,
          name: '锁定'
        },
        {
          id: 4,
          name: '异常'
        },
        {
          id: 5,
          name: '禁用'
        },
      ],
      editHw: false
    }
  },
  methods: {
    showEdit(row) {
      if (!row) {
        this.title = '新增'
        this.editHw = false
      } else {
        this.title = '编辑'
        this.form = Object.assign({}, row)
      }
      this.dialogFormVisible = true
    },
    close() {
      this.$refs['form'].resetFields()
      this.form = this.$options.data().form
      this.dialogFormVisible = false
    },
    save() {
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          if (this.title == '编辑') {
            const { msg } = await UptHuowei(this.form)
          } else {
            const { msg } = await AddHuowei(this.form)
          }
          this.$baseMessage('操作成功', 'success')
          this.$emit('fetch-data')
          this.close()
        } else {
          return false
        }
      })
    },
  },
}
</script>
<style lang="scss" scoped>
.el-select {
  width: 100%;
}
</style>
